package com.servlet;

import com.dao.StudentDao;
import com.util.SpringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/admin/upStu")
public class updStu extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int sid = Integer.parseInt(req.getParameter("sid"));
        String sname = req.getParameter("sname");
        String ssex = req.getParameter("ssex");
        Date birth=null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            birth = simpleDateFormat.parse(req.getParameter("birth"));
        } catch (ParseException e) {
        }

        StudentDao studentDao = SpringUtil.getBean(StudentDao.class);
        int i = studentDao.updStu(sid, sname, ssex, birth);
        PrintWriter writer = resp.getWriter();
        writer.write(i+"");
        writer.close();

    }
}
